package com.geek.netty.inbound;

import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.http.HttpObjectAggregator;
import io.netty.handler.codec.http.HttpServerCodec;

import java.util.List;

/**
 * @program geek
 * @description: init
 * @author: chanzhugang
 * @create: 2021/04/03 00:18
 */
public class HttpInboundInitailizer extends ChannelInitializer<SocketChannel> {

    private List<String> proxyService;

    public HttpInboundInitailizer(List<String> proxyService) {
        this.proxyService = proxyService;
    }

    @Override
    protected void initChannel(SocketChannel ch) {
        // 处理器链
        ChannelPipeline pipeline = ch.pipeline();
        pipeline.addLast(new HttpServerCodec());
        pipeline.addLast(new HttpObjectAggregator(1024 * 1024));
        // 入站
        pipeline.addLast(new HttpInboundHandler(this.proxyService));
    }
}